#include<vector>

using std::vector;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};



class Solution {
public:
    int maxDepth(TreeNode* root) {
        // 遍历一下就可以
        if (root == nullptr) return 0;
        
        vector<TreeNode*> layer = {root};
        int layerNum = 0;
        while (!layer.empty()) {
            layerNum++;
            vector<TreeNode*> newLayer = {};
            for (auto t: layer) {
                
                if (t->left) newLayer.push_back(t->left);
                if (t->right) newLayer.push_back(t->right);
            }
            layer = newLayer;
        }
        return layerNum;
    }
};